package org.zeapp.opencloud.framework.cloud;

public class CloudException extends Exception {

	/**
	 * An exception that provide information on a cloud failure. Each
	 * CloudException provide the following information
	 * <UL>
	 * <LI>a string description of the exception
	 * <LI>a "faultCode" to identify the exception (easier to speak about
	 * exception than using the string message)
	 * </UL>
	 */

	/** the serial UID */
	private static final long serialVersionUID = 1L;

	/** The fault code */
	private String faultCode;

	/**
	 * Create a new CloudException.
	 * 
	 * @param message
	 *            the description
	 * @param faultCode
	 *            the linked fault code. Fault Code starting with "ZECLD" are
	 *            reserved for the Cloud framework. Any cloud service provider
	 *            must use its own fault code and must not start with "ZECLD".
	 */
	public CloudException(String message, String faultCode) {
		super(message);
		this.faultCode = faultCode;
	}

	/**
	 * Create a new CloudException.
	 * 
	 * @param message
	 *            the description
	 * @param faultCode
	 *            the linked fault code. Fault Code starting with "ZECLD" are
	 *            reserved for the Cloud framework. Any cloud service provider
	 *            must use its own fault code and must not start with "ZECLD".
	 * @param cause
	 *            the the underlying reason for this CloudException (which is
	 *            saved for later retrieval by the getCause() method); may be
	 *            null indicating the cause is non-existent or unknown.
	 */
	public CloudException(String message, String faultCode, Throwable cause) {
		super(message, cause);
		this.faultCode = faultCode;
	}

	/**
	 * Return the fault code for this CloudException object.
	 * 
	 * @return the fault code
	 */
	public String getFaultCode() {
		return faultCode;
	}

	/**
	 * Return the concatenation of the fault code and the message description,
	 * or the only the message description if the fault code is null.
	 */
	@Override
	public String getMessage() {
		if (faultCode == null) {
			return super.getMessage();
		} else {
			return faultCode + " - " + super.getMessage();
		}
	}

	/**
	 * Return the message description without the fault code.
	 * 
	 * @return the message description
	 */
	public String getMessageDescription() {
		return super.getMessage();

	}
}
